package cn.tlb.gl.game.rebuild2;

import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.Toast;

import cn.tlb.BaseGLActivity;

public class GameModelActivity extends BaseGLActivity {
    private ModelRenderer renderer;
    {
        Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread thread, Throwable ex) {
                System.out.println("uncaughtException");
                ex.printStackTrace();

                if (thread.getName().contains("GLThread")) {
                    System.out.println("GLThread uncaughtException");
                    Toast.makeText(getApplicationContext(), "无法使用3D预览", Toast.LENGTH_SHORT).show();
                } else if(ex instanceof RuntimeException) {
                    System.out.println("RuntimeException uncaughtException");
                    Toast.makeText(GameModelActivity.this, ex.getMessage(), Toast.LENGTH_SHORT).show();
                }
                finish();
            }
        });
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        renderer = new ModelRenderer(this);
        // We want an 8888 pixel format because that's required for
        // a translucent window.
        // And we want a depth buffer.
        //mGlSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
        mGlSurfaceView.setRenderer(renderer);
        // Use a surface format with an Alpha channel:
        //mGlSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
        setContentView(mGlSurfaceView);
    }

    @Override
    public boolean onTouchEvent(MotionEvent e) {
        super.onTouchEvent(e);
        renderer.setAngleX(mAngleX);
        renderer.setAngleY(mAngleY);
        return true;
    }
}
